package com.desire.mapper;

import com.desire.entity.Roles;
import com.desire.entity.User;
import com.desire.entity.Users;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;
import java.util.Map;

/**
 * @author LittleDesire
 * @description
 * @date 2022-04-14 周四 18:16
 * @since 17
 */
@Mapper
public interface UserMapper {



    /*一对一查询测试 和*/
    User query(String name);




     /*一对多查询测试*/
    User select(String name);


    /*多对多查询测试*/
    Users se(String name);
    List<Users> qa();

    /*多对多注解方式*/
    @Select("select * from oadb.w_roles where name = #{name}")
    @Results(id = "rolesmap", value = {
            @Result(id = true, property = "id", column = "id"),
            @Result(property = "name", column = "name"),
            @Result(property = "users", column = "id",
                    many = @Many(select = "selrole", fetchType = FetchType.LAZY))
    })
    Roles queryByNamed(String name);

    @Select("select wr.id,wr.name,wr.password from oadb.w_users_roles wu join oadb.w_users wr on wu.role_id = ${id} and wr.id = wu.user_id")
    List<Map<String, Object>> selrole(int id);


    @Select("select * from oadb.w_roles")
    @ResultMap("rolesmap")
    List<Roles> queryAll();



}
